#!/usr/bin/env python
# -*- coding: utf-8 -*-

import wx
import VarGlobales


ID_WIDTHPEN = 15
ID_COLORPEN = 159
ID_COLORBACKGROUND = 160
ID_FONT = 161
ID_ACPT = 302
ID_CANC = 303


class FrmConfiguracion(wx.Dialog):
    def __init__(self, parent, font, colorfont, selwidthpen, selmodeexecute):
        wx.Dialog.__init__(self, parent, -1, 'Configuracion Entorno', size = (250, 310))
        
        
        self.font = font
        self.colorfont = colorfont
        self.selwidthpen = selwidthpen
        self.selModeExecute = selmodeexecute
        
        self.d1 = False
        self.d2 = False
        
        self.Inicializar()
        self.eventos()
        
        
        
    def Inicializar(self):
        
        wx.StaticText(self, label = "CONFIGURACION", pos = (15,15))
        
        wx.StaticText(self, label = "Fuente", pos = (15,50))
        self.BtnFont = wx.Button(self, ID_FONT, "...", pos = (60,45), size=(30,20))
        
        wx.StaticText(self, label = "Color de fondo", pos = (110,50))
        self.BtnColorBack = wx.Button(self, ID_COLORBACKGROUND, "...", pos = (190,45), size=(30,20))
        
        wx.StaticText(self, label = "LAPIZ", pos = (15,90))
        sampleList = ['1', '2', '3', '4', '5', '6','7', '8', '9', '10']
        wx.StaticText(self,  label = "Tamaño", pos = (15, 125))
        self.combo = wx.ComboBox(self, -1, str(int(self.selwidthpen)+1), (60, 120), wx.DefaultSize,sampleList, wx.CB_DROPDOWN)
        wx.StaticText(self, label = "Color", pos = (120,125))
        BtnColorPen = wx.Button(self, ID_COLORPEN, "...", pos = (155,120), size=(30,20))
        
        wx.StaticText(self, label = "MODO DE EJCUCION", pos = (15,165))
        
        List = ['simulacion', 'Programar robot']
        self.radiobox = wx.RadioBox(self, -1, "", (15, 185), wx.DefaultSize, List, 2, wx.RA_SPECIFY_COLS | wx.NO_BORDER)
        self.radiobox.SetSelection(self.selModeExecute)
        
        BtnAceptar = wx.Button(self, ID_ACPT, "Aceptar", (40, 240)) 
        BtnCancelar = wx.Button(self, ID_CANC, "Cancelar", (130, 240))
        
        
        
    def eventos(self):
        wx.EVT_BUTTON(self, ID_FONT, self.OnFont)
        wx.EVT_BUTTON(self, ID_COLORBACKGROUND, self.OnColorBackground)
        wx.EVT_BUTTON(self, ID_COLORPEN, self.OnColorPen)
        wx.EVT_BUTTON(self, ID_ACPT, self.OnAceptar)
        wx.EVT_BUTTON(self, ID_CANC, self.OnCancelar)
        
    def  GetFont(self):
        return self.font
    
    def GetColorFont(self):
        return self.colorfont
    
    def GetWidthPen(self):
        return self.selwidthpen
    
    def GetModeExecute(self):
        return self.selModeExecute
        
    def OnFont(self, event):
        dialog = wx.FontDialog(self, wx.FontData())
        if dialog.ShowModal() == wx.ID_OK:
            data = dialog.GetFontData()
            self.font = data.GetChosenFont()
            self.colorfont = data.GetColour()
        dialog.Destroy()
    
    def OnColorPen(self, event):
        dialog = wx.ColourDialog(self)
        dialog.GetColourData().SetChooseFull(True)
        if dialog.ShowModal() == wx.ID_OK:
            self.data1 = dialog.GetColourData()
            self.d1 = True
        dialog.Destroy()
        
    def OnColorBackground(self,event):
        dialog = wx.ColourDialog(self)
        dialog.GetColourData().SetChooseFull(True)
        if dialog.ShowModal() == wx.ID_OK:
            self.data2 = dialog.GetColourData()
            self.d2 = True
        dialog.Destroy()
        
    def OnAceptar(self, event):
        self.selModeExecute = self.radiobox.GetSelection()
        self.selwidthpen = self.combo.GetCurrentSelection()
        if self.d1:
            VarGlobales.canvas.SetColorPen(self.data1.GetColour().Get())
        if self.d2:
            VarGlobales.canvas.SetColorSurface(self.data2.GetColour().Get())
        self.Close() 
        
    def OnCancelar(self, event):
        self.Close() 
    